import java.util.ArrayDeque;
import java.util.Deque;

class Solution2 {
    public int evalRPN(String[] tokens) {
        Deque<Integer> stack = new ArrayDeque<>();
        for (String token : tokens) {
            if(token.equals("+")){
                stack.push(stack.pop() + stack.pop());
            }else if(token.equals("-")){
                stack.push(-stack.pop() + stack.pop());
            }else if(token.equals("*")){
                stack.push(stack.pop() * stack.pop());
            }else if(token.equals("/")){
                stack.push(1/stack.pop() * stack.pop());
            }else {
                stack.push(Integer.parseInt(token));
            }
        }
        return stack.pop();
    }
}